<template>
  <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="8">
        <el-date-picker
          v-model="time"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-col>
      <el-col :span="4">
        <template>
          <el-select 
            v-model="status"
            clearable
            placeholder="代金券状态">
            <el-option
              v-for="item in statusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="4">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="onSearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <!-- <el-table-column
            type="selection"
            width="55">
          </el-table-column> -->
          <el-table-column
            label="序号"
            type="index"
            width="100">
          </el-table-column>
          <!-- <el-table-column
            prop="COUPONNAME"
            label="分类名称"
            >
          </el-table-column> -->
          <el-table-column
            prop="USER_NAME"
            label="邀请人"
            >
          </el-table-column> 
          <el-table-column
            prop="SHAREUSERNAME"
            label="被邀请人"
            >
          </el-table-column> 
          <el-table-column
            prop="COST"
            label="抵扣面值"
            >
          </el-table-column> 
          <el-table-column
            prop="REQFEE"
            label="要求金额"
            >
          </el-table-column> 
          <el-table-column
            prop="GETTIME"
            label="获取时间"
            >
          </el-table-column> 
          <el-table-column
            prop="USETIME"
            label="使用时间"
            >
          </el-table-column> 
          <el-table-column
            prop="BEGINTIME"
            label="有效开始时间"
            >
          </el-table-column> 
          <el-table-column
            prop="ENDTIME"
            label="有效结束时间"
            >
          </el-table-column> 
          <el-table-column
            prop="GETDESC"
            label="备注"
            >
          </el-table-column> 
          <el-table-column
            label="状态"
            >
            <template scope="scope">
              {{scope.row.STATUS | onStatus}}
            </template>
          </el-table-column>
        </el-table>
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>   
  </div>
</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myColorRed{
    color: #f00;
  }
</style>

<script>
  import { getUserCouponList } from '@/api/online';
  import qs from "querystring";

  export default {
    data(){
      return{  
        title:"用户代金券",    
        loading:false,
        tableData:[],  
        total:null, //总条数  
        page_num: 1, //当前页码
        page_size: 10, //每页显示多少条 
        kw:"",
        startTime:"",
        endTime:"",
        status:"",
        statusList:[{label:"未使用",value:0},{label:"已使用",value:1},{label:"已过期",value:2}],
        time:[]
      }
    },
    created() {
      document.title=this.title;
      this.onGetUserCouponList();
    },
    filters: {
      onStatus(val){
        let status={
          0:"未使用",
          1:"已使用",
          2:"已过期"
        }
        return status[val];
      }
    },
    methods:{
       onGetUserCouponList() {//拉取列表
        let vm = this;
        if(vm.time){
          vm.startTime=this.time[0];
          vm.endTime=this.time[1];
        }else{
          vm.startTime="";
          vm.endTime="";
        }
        const params = {
          rows:vm.page_size,
          page:vm.page_num,
          NAME:encodeURI(vm.kw),
          start:vm.startTime,
          end:vm.endTime,
          STATUS:vm.status
        }
        vm.loading=true;
        getUserCouponList(params)
        .then(response => {
          let res = response.data;
          vm.tableData = res.rows;
          vm.total = res.total;
          vm.loading=false;
        })
        .catch(error => {
          vm.loading=false;
          console.log("拉取列表失败",error);
        });
      },
      handleSizeChange(val) {
        this.page_size = val;
        this.onGetUserCouponList();
      },
      handleCurrentChange(val) {
        this.page_num = val;
        this.onGetUserCouponList();
      },
      handleSelectionChange(val) {
      },
      onSearch(){//查询
        this.onGetUserCouponList();
      }
    }

  }


</script>



